package com.djq.project.mq.producer.publisherConfirms;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
public class SendPublisherConfirms {


    public final static String  DIRECT_EXCHANGE="publisherConfirms_exchange";
    public final static String  DIRECT_EXCHANGE_QUEUE="publisherConfirmsQueue";


    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/sendPublisherConfirms")
    public String sendPublisherConfirms(String msg){
        String uuid = UUID.randomUUID().toString();
        Message message = new Message(msg.getBytes(),null);

        rabbitTemplate.send(DIRECT_EXCHANGE,DIRECT_EXCHANGE_QUEUE,message,new CorrelationData(uuid));
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "消息已发送";
    }
}
